<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>添加/编辑授课</title>
    <link rel="stylesheet" href="layui/css/layui.css" media="all">
</head>
<body>
<fieldset class="layui-elem-field layui-field-title"
          style="margin-top: 50px;">
    <legend>授课编辑</legend>
</fieldset>
<form  class="layui-form layui-form-pane" >
    <input type="hidden" name="lectureId"  >


    <div class="layui-form-item">
        <label class="layui-form-label">教师编号</label>
        <div class="layui-input-inline">
            <input id="teacherNo" name="teacherNo" lay-verify="required" placeholder="请选择教师"
                   autocomplete="off" class="layui-input" type="text">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">班级编号</label>
        <div class="layui-input-inline">
            <input id="clazzNo" name="clazzNo" lay-verify="required" placeholder="请选择班级"
                   autocomplete="off" class="layui-input" type="text">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">课程名</label>
        <div class="layui-input-inline">
            <input id="courseName" name="courseName" lay-verify="required" placeholder="请选择课程"
                   autocomplete="off" class="layui-input" type="text">
        </div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label">院系</label>
        <div class="layui-input-inline">
            <input id="departmentName" name="departmentName" lay-verify="required" placeholder="请选择院系"
                   autocomplete="off" class="layui-input" type="text">
        </div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label">学期</label>
        <div class="layui-input-inline">
            <input id="semesterName" name="semesterName" lay-verify="required" placeholder="请选择学期"
                   autocomplete="off" class="layui-input" type="text">
        </div>
    </div>





    <div class="layui-form-item">
        <button class="layui-btn" lay-submit="" lay-filter="form1" >提交</button>
    </div>

</form>

<script src="layui/layui.js"></script>
<script src="layui/layui.all.js"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->

<script src="layui/lay/modules/tableSelect.js"></script>

<script type="text/javascript">

    var tableSelect = layui.tableSelect;

    /** 监听教师编号input框 */
    tableSelect.render({
        elem: '#teacherNo',
        searchKey: 'username',	//搜索输入框的name值 默认keyword
        searchPlaceholder: '姓名搜索',	//搜索输入框的提示文字 默认关键词搜索
        table: {
            url:'/evaluation/user/findTeachers',
            cols: [[
                { type: 'radio' },
                { field: 'userNo', title: '教师编号' },
                { field: 'username', title: '教师名' }
            ]],
            cellMinWidth : 80, //全局定义常规单元格的最小宽度，layui 2.2.1 新增
            height: 200,
            page : true,
            limits : [ 3, 5, 10 ],
        },
        done: function (elem, data) {
            var NEWJSON = []
            layui.each(data.data, function (index, item) {
                NEWJSON.push(item.userNo)
            })
            elem.val(NEWJSON.join(","))
        }
    });


    /** 监听班级编号input框 */
    tableSelect.render({
        elem: '#clazzNo',
        searchKey: 'clazzName',	//搜索输入框的name值 默认keyword
        searchPlaceholder: '课程名搜索',	//搜索输入框的提示文字 默认关键词搜索
        table: {
            url:'/evaluation/clazz/list',
            cols: [[
                { type: 'radio' },
                { field: 'clazzNo', title: '班级编号' },
                { field: 'clazzName', title: '班级名' }
            ]],
            cellMinWidth : 80, //全局定义常规单元格的最小宽度，layui 2.2.1 新增
            height: 200,
            page : true,
            limits : [ 3, 5, 10 ],
        },
        done: function (elem, data) {
            var NEWJSON = []
            layui.each(data.data, function (index, item) {
                NEWJSON.push(item.clazzNo)
            })
            elem.val(NEWJSON.join(","))
        }
    });


    /** 监听课程名input框 */
    tableSelect.render({
        elem: '#courseName',
        searchKey: 'courseName',	//搜索输入框的name值 默认keyword
        searchPlaceholder: '课程名搜索',	//搜索输入框的提示文字 默认关键词搜索
        table: {
            url:'/evaluation/course/list',
            cols: [[
                { type: 'radio' },
                { field: 'cnum', title: '课程编号' },
                { field: 'courseName', title: '课程名' }
            ]],
            cellMinWidth : 80, //全局定义常规单元格的最小宽度，layui 2.2.1 新增
            height: 200,
            page : true,
            limits : [ 3, 5, 10 ],
        },
        done: function (elem, data) {
            var NEWJSON = []
            layui.each(data.data, function (index, item) {
                NEWJSON.push(item.courseName)
            })
            elem.val(NEWJSON.join(","))
        }
    });


    /** 监听院系input框 */
    tableSelect.render({
        elem: '#departmentName',
        searchKey: 'departmentName',	//搜索输入框的name值 默认keyword
        searchPlaceholder: '院系名搜索',	//搜索输入框的提示文字 默认关键词搜索
        table: {
            url:'/evaluation/department/list',
            cols: [[
                { type: 'radio' },
                { field: 'departmentNo', title: '院系编号' },
                { field: 'departmentName', title: '院系名称' }
            ]],
            cellMinWidth : 80, //全局定义常规单元格的最小宽度，layui 2.2.1 新增
            height: 200,
            page : true,
            limits : [ 3, 5, 10 ],
        },
        done: function (elem, data) {
            var NEWJSON = []
            layui.each(data.data, function (index, item) {
                NEWJSON.push(item.departmentName)
            })
            elem.val(NEWJSON.join(","))
        }
    });



    /** 监听学期input框 */
    tableSelect.render({
        elem: '#semesterName',
        searchKey: 'semesterName',	//搜索输入框的name值 默认keyword
        searchPlaceholder: '院系名搜索',	//搜索输入框的提示文字 默认关键词搜索
        table: {
            url:'/evaluation/semester/list',
            cols: [[
                { type: 'radio' },
                { field: 'semesterName', title: '学期名称' }
            ]],
            cellMinWidth : 80, //全局定义常规单元格的最小宽度，layui 2.2.1 新增
            height: 200,
            page : true,
            limits : [ 3, 5, 10 ],
        },
        done: function (elem, data) {
            var NEWJSON = []
            layui.each(data.data, function (index, item) {
                NEWJSON.push(item.semesterName)
            })
            elem.val(NEWJSON.join(","))
        }
    });
</script>


<script type="text/javascript">
    layui.use(["form", "layer", "jquery"], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;


        /* function parseUrl(){
             var url=location.href;
             var i=url.indexOf('?');
             if(i==-1)return;
             var querystr=url.substr(i+1);
             var arr1=querystr.split('&');
             var arr2=new Object();
             for  (i in arr1){
                 var ta=arr1[i].split('=');
                 arr2[ta[0]]=ta[1];
             }
             return arr2;
         }
         var v = parseUrl();//解析所有参数
         // alert(v['userId']);//就是你要的结果
         var */

        var Ohref=window.location.href;
        var arrhref=Ohref.split("?lectureId=");
        // alert(arrhref[1]);
        var lectureId = arrhref[1];


        (function(){
            if (lectureId !== undefined) {         //判断我是点的添加还是编辑
                /*此处是在编辑的时候根据roleId在后台查询用户的全部信息并数据回显*/
                $.ajax({
                    url:"/evaluation/lecture/findByLectureId",
                    type:"get",
                    data:{lectureId:lectureId},
                    dataType:"json",
                    success:function(data){
                        var lecture = data.data;

                        // $("#userInfo").text(username + "    " + userNo);
                        // window.location.href ="login.html";
                        $("input[name='lectureId']").val(lecture.lectureId);
                        $("input[name='teacherNo']").val(lecture.teacherNo);
                        $("input[name='clazzNo']").val(lecture.clazzNo);
                        $("input[name='courseName']").val(lecture.courseName);
                        $("input[name='departmentName']").val(lecture.departmentName);
                        $("input[name='semesterName']").val(lecture.semesterName);

                    },
                    error:function(xmlHttpRequest,textStatus,errorThrown){
                        alert(textStatus+"出错！"+errorThrown);
                    }
                });
            }
        })();



        form.on("submit(form1)", function (data) {
            /* layer.alert(($("#userId").val()==null || $("#userId").val()=='') ? "添加成功!" : "修改成功!", {icon: 1}); */
            $.post("/evaluation/lecture/save", data.field,function(d){
                if (d.code === 15 || d.code === 16){
                    layer.msg("很抱歉！操作失败了。",{icon: 5,time: 1500},function(){
                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.layer.close(index); //再执行关闭
                    });
                }else if (d.code === 0) {
                    layer.msg("恭喜您！操作成功了。",{icon: 6,time: 1500},function(){
                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.layer.close(index); //再执行关闭
                    });
                }
            },"json");




            return false;
        });








    });
</script>
</body>
</html>